

#include <stdint.h>
#include "sensorsTask.h"
#include "FreeRTOS.h"
#include "task.h"

#include "nxbot.h"


static void sensorsTask(void *pvParameters);


void executeSensorsTask(general *pvParameters)
{

	xTaskCreate(sensorsTask,(const signed portCHAR * const)"iRSnTask",sensorsTask_stackSize,(void *)pvParameters,tskIDLE_PRIORITY + 2,( xTaskHandle * ) NULL);
}

//tarea que solo actualiza la info de los sensores IR
//TODO: polling de bumpers, y de bateria????
static void sensorsTask(void *pvParameters)
{	
	//convertion of parameters 
	general *globals;
	globals=(general *)pvParameters;
	
	//delay
	unsigned int freq;
	portTickType actualTick;

	//static unsigned char temp=0;
	for(;;)
	{
		//obtain the frequency of the IRSensors update
		//taskENTER_CRITICAL();
		freq=globals->gTimes.intervalSensors;
		//taskEXIT_CRITICAL();

		//acquire values of IRs	
		//temp = sensors_getIR();
		
		//update sensor value
		//taskENTER_CRITICAL();
		//globals->gSensors.sensorsIR = temp;	
		//taskEXIT_CRITICAL();
		
		sensors_readAll(&(globals->gSensors));

		
		//time delay according to the irSensorsInterval value
		
		actualTick = xTaskGetTickCount();			
		vTaskDelayUntil( &actualTick,(portTickType)freq);	



	}
}
